package com.ptt.sqm.ws;

import org.ksoap2.serialization.PropertyInfo;

import android.os.AsyncTask;
import android.util.Log;

public class DefaultTask extends AsyncTask<PropertyInfo, Void, Object> {				
    
	private IDefaulCall com;
	
	private String method;
	
	public AsyncResponse delegate;
	
	protected Object[] obj;

	public DefaultTask(IDefaulCall com, String method) {
		this.com = com;
		this.method = method;
	}

	public DefaultTask(IDefaulCall com, String method, Object... obj) {
		this.com = com;
		this.method = method;
		this.obj = obj;
	}
	
	@Override
	protected Object doInBackground(PropertyInfo... params) {
		// TODO: attempt authentication against a network service.	 
		try{
			return com.execute(method, params);
		} catch(Exception e) {
			Log.i("call service", e.getMessage());
		}
		return null;
	}

	@Override
	protected void onPostExecute(final Object success) {		
		if(obj != null)
			delegate.processFinish(method, success, obj);
		else
			delegate.processFinish(method, success);
	}
	
	public void setMethod(String method) {
		this.method = method;
	}

}		
